package com.adminsystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.adminsystem.entity.SysMenu;
import com.adminsystem.service.SysMenuService;
import com.adminsystem.mapper.SysMenuMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_menu(菜单表)】的数据库操作Service实现
* @createDate 2023-09-22 16:53:13
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
    implements SysMenuService{

    @Override
    public List<SysMenu> buildTreeMenu(List<SysMenu> sysMenuList) {
        List<SysMenu> resultMenuList=new ArrayList<>();
        for (SysMenu sysMenu:sysMenuList) {
            for (SysMenu e:sysMenuList) {
                    if(e.getParentId()==sysMenu.getId()){
                        sysMenu.getChildren().add(e);
                    }
            }
            if(sysMenu.getParentId()==0L){
                resultMenuList.add(sysMenu);
            }
        }
        return resultMenuList;
    }
}




